<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>06.vue非父子组件间传值(Bus/总线/发布订阅/观察者模式)</title>
</head>
<body>
    <div id="app">
        <child content="Dell"></child>
        <child content="Lee"></child>
    </div>
</body>
<script src="vue.js"></script>
<script>
    Vue.prototype.bus = new Vue();
    Vue.component('child', {
        props: {
            content: String
        },
        data: function() {
            return {
                msg: this.content
            }
        },
        template: '<div  @click="handleClick">{{msg}}</div>',
        methods: {
            handleClick() {
               // alert(this.content)
               // 自定触发事件
               this.bus.$emit('change', this.content)
            }
        },
        mounted: function() {
            // 监听事件
            var this_ = this
            this.bus.$on('change', function(msg){
                this_.msg = msg
            })
        }
    })
    var app = new Vue({
        el: '#app',
        data: {
            content: 'hello world!',
        }
    })
</script>
</html>